package com.ctg.payroll2.action.cusadmin;



import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.ctg.payroll2.bean.po.PbUserAccount;
import com.ctg.payroll2.service.cusadmin.PbCompanyService;
import com.ctg.payroll2.service.cusadmin.PbUserAccountService;
import com.ctg.platform.util.Page;
import com.opensymphony.xwork2.ActionSupport;

public class PbUserAccountAction extends ActionSupport {


	private Page result;

	public void setResult(Page result) {
		this.result = result;
	}

	
	
	// 创建客户管理员账号
	public String insertPbUserAccount() {
		String userCode;
		String userPwd;
		String companyCode;
		HttpServletRequest request = ServletActionContext.getRequest();
		userCode = request.getParameter("user_code");
		userPwd = request.getParameter("user_pwd");
		companyCode=request.getParameter("company_code");
		PbUserAccount p = new PbUserAccount();
		p.setCompany_code(companyCode);
		p.setUser_code(userCode);
		p.setUser_pwd(userPwd);
		p.setUser_name(userCode);
		try {
			WebApplicationContext wac=WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
			PbUserAccountService pbaccountService=(PbUserAccountService) wac.getBean("pbUserAccountService");
			pbaccountService.insertPbUserAccount(p);
			PbCompanyService pbCompanySevice=(PbCompanyService) wac.getBean("companyService");
			pbCompanySevice.updateStatus(companyCode);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	return SUCCESS;
	}

}
